<template>
  <div class="register-container">
    <!-- 注册内容 -->
    <div class="register">
      <h3>
        注册新用户
        <span class="go"
          >我有账号，去 <router-link to="/login">登录</router-link>
        </span>
      </h3>
      <div class="content">
        <label>用户名:</label>
        <input type="text" placeholder="请输入你的用户名" v-model="username" />
        <span class="error-msg"> </span>
      </div>
      <div class="content">
        <label>登录密码:</label>
        <input
          type="password"
          placeholder="请输入你的密码"
          v-model="password"
        />

        <span class="error-msg"> </span>
      </div>
      <div class="content">
        <label>确认密码:</label>
        <input
          type="password"
          placeholder="请输入确认密码"
          v-model="confirmPassword"
        />

        <span class="error-msg"> </span>
      </div>
      <div class="controls">
        <span class="error-msg"> </span>
      </div>
      <div class="btn">
        <button @click="userRegister">完 成 注 册</button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "Register",
  data() {
    return {
      // 用户名称
      username: "",
      //密码
      password: "",
      //确认密码
      confirmPassword: "",
      // 用户id
      id: null,
    };
  },

  methods: {
    //用户注册
    userRegister() {
      const { password, username, id, confirmPassword } = this;
      username && password && password == confirmPassword;

      this.$store.dispatch("addUserRegisteer", { username, password, id });
    },
  },
};
</script>

<style lang="less" scoped>
.register-container {
  margin-top: 80px;
  .register {
    width: 600px;
    height: 400px;
    border: 1px solid rgb(223, 223, 223);
    margin: 0 auto;

    h3 {
      background: #ececec;
      margin: 0;
      padding: 6px 15px;
      color: #333;
      border-bottom: 1px solid #dfdfdf;
      font-size: 20.04px;
      line-height: 30.06px;

      span {
        font-size: 14px;
        float: right;

        a {
          color: #374a74;
        }
      }
    }

    div:nth-of-type(1) {
      margin-top: 40px;
    }

    .content {
      padding-left: 100px;
      margin-bottom: 20px;
      position: relative;

      label {
        font-size: 14px;
        width: 96px;
        text-align: right;
        display: inline-block;
      }

      input {
        width: 270px;
        height: 38px;
        padding-left: 8px;
        box-sizing: border-box;
        margin-left: 5px;
        outline: none;
        border: 1px solid #999;
      }

      img {
        vertical-align: sub;
      }
    }

    .btn {
      text-align: center;
      line-height: 40px;
      height: 40px;
      margin-top: 40px;
      background-color: #374a74;
      button {
        outline: none;
        width: 100%;
        height: 36px;
        background: #374a74;
        color: #fff !important;
        display: inline-block;
        font-size: 18px;
        border: none;
      }
    }
  }
}
</style>
